<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>14 二级菜单</title>
    <script src="./js/vue.js"></script>
</head>
<body>
    <div id="app">
        <ul>
            <li v-for="item in list" @click="reactive(item.id)">{{item.msg}}
                <ul v-if="item.id == activeIndex">
                    <li v-for="info in item.list">{{info.msg}}</li>
                </ul>
            </li>
        </ul>
    </div>

    
</body>
<script>
    new Vue({
        el : "#app",
        data : {
            activeIndex : 0,
            list : [
                    {id:1 , msg:"菜单一" , list:[{id:11 , msg:"菜单1-1"} , {id:12 , msg:"菜单1-2"}]} , 

                    {id:2 , msg:"菜单二" , list:[{id:21 , msg:"菜单2-1"} , {id:22 , msg:"菜单2-2"}]} , 
                    
                    {id:3 , msg:"菜单三" , list:[{id:11 , msg:"菜单3-1"} , {id:11 , msg:"菜单3-2"}]}
                ],
            
        },
        methods : {
            reactive(id){
                if(this.activeIndex == id){
                    this.activeIndex = 0;
                }else{
                    this.activeIndex = id;
                }
            }

        }
    })
</script>
</html>